package cn.edu.jnu.x2022103715;

import android.annotation.SuppressLint;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.util.Arrays;

public class MainActivity extends AppCompatActivity {

    private EditText inputField;
    private TextView resultView;

    @SuppressLint("WrongViewCast")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 绑定控件
        inputField = findViewById(R.id.inputField);
        resultView = findViewById(R.id.resultView);
        Button submitButton = findViewById(R.id.submitButton);

        // 按钮点击事件
        submitButton.setOnClickListener(v -> {
            // 获取输入内容
            String input = inputField.getText().toString().trim();
            if (input.isEmpty()) {
                resultView.setText("请输入测试用例编号！");
                return;
            }

            try {
                int testCase = Integer.parseInt(input);
                int[] result = ArrayGenerator.generate(testCase);
                if (result == null) {
                    resultView.setText("无效的测试用例编号！");
                } else {
                    resultView.setText(Arrays.toString(result));
                }
            } catch (NumberFormatException e) {
                resultView.setText("请输入有效的数字！");
            }
        });
    }
}